package com.rockxin.cat.network;

import com.rockxin.cat.bean.BannerBean;
import com.rockxin.cat.bean.BidDetailsBean;
import com.rockxin.cat.bean.CapitalLogBean;
import com.rockxin.cat.bean.FyBean;
import com.rockxin.cat.bean.LendRecordBean;
import com.rockxin.cat.bean.MyBankCardBean;
import com.rockxin.cat.bean.NoticeListBean;
import com.rockxin.cat.bean.RechargeBean;
import com.rockxin.cat.bean.RecommendAwardBean;
import com.rockxin.cat.bean.RedPacketBean;
import com.rockxin.cat.bean.UseBean;
import com.rockxin.cat.bean.UserBean;

import java.util.HashMap;
import java.util.List;

import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.Part;
import retrofit2.http.Query;
import retrofit2.http.QueryMap;
import rx.Observable;
import rx.Subscriber;

/**
 * <b>类名称：    CatNetWork             <br/>
 * <b>类描述：                        <br/>
 * <b>创建人：    Lans               <br/>
 * <b>创建时间：  2018/3/5 12:04     <br/>
 * <b>修改人：                        <br/>
 * <b>修改时间：                      <br/>
 * <b>修改备注：                      <br/>
 *
 * @version 1.0.0 <br/>
 */
public class CatNetWork {
    private final NetApi netApi;

    public CatNetWork() {
        netApi = RetrofitUtils.getInstance().create(NetApi.class);
    }

    /**
     * 注册
     */
    public void regist(@Query("username") String username, @Query("password") String password, @Query("mobile_email") String mobile_email, @Query("code") String code, Subscriber<HttpResult> subscriber) {
        final Observable<HttpResult> regist = netApi.regist(username, password, mobile_email, code);
        RetrofitUtils.getInstance().toSubscribe(regist, subscriber);
    }

    /**
     * 手机邮箱注册验证码接口
     */
    public void sendCode(@Query("user_mobile") String user_mobile, Subscriber<HttpResult> subscriber) {
        final Observable<HttpResult> regist = netApi.sendCode(user_mobile);
        RetrofitUtils.getInstance().toSubscribe(regist, subscriber);
    }

    /**
     * 登录
     */
    public void login(@Query("mobile_email") String mobile_email, @Query("password") String password, Subscriber<HttpResult<UseBean>> subscriber) {
        final Observable<HttpResult<UseBean>> regist = netApi.login(mobile_email, password);
        RetrofitUtils.getInstance().toSubscribe(regist, subscriber);
    }

    /**
     * 找回密码验证码
     */
    public void sendCodeReset(@Query("user_mobile") String user_mobile, Subscriber<HttpResult> subscriber) {
        final Observable<HttpResult> regist = netApi.sendCodeReset(user_mobile);
        RetrofitUtils.getInstance().toSubscribe(regist, subscriber);
    }

    /**
     * 重置密码
     */
    public void resetPasswd(@Query("mobile_email") String mobile_email, @Query("password") String password, @Query("repassword") String repassword, @Query("code") String code, Subscriber<HttpResult> subscriber) {
        final Observable<HttpResult> regist = netApi.resetPasswd(mobile_email, password, repassword, code);
        RetrofitUtils.getInstance().toSubscribe(regist, subscriber);
    }

    /**
     * 修改登录密码接口
     */
    public void modifyLoginPasswd(@Query("token") String token, @Query("mobile_email") String mobile_email, @Query("password") String password, @Query("repassword") String repassword, @Query("code") String code, Subscriber<HttpResult> subscriber) {
        final Observable<HttpResult> regist = netApi.modifyLoginPasswd(token, mobile_email, password, repassword, code);
        RetrofitUtils.getInstance().toSubscribe(regist, subscriber);
    }

    /**
     * 公告列表接口
     */
    public void noticeList(Subscriber<HttpResult<List<NoticeListBean>>> subscriber) {
        final Observable<HttpResult<List<NoticeListBean>>> regist = netApi.noticeList();
        RetrofitUtils.getInstance().toSubscribe(regist, subscriber);
    }

    /**
     * 公告列表详情
     */
    public void noticeInfo(@Query("id") String id, Subscriber<HttpResult<UseBean>> subscriber) {
        final Observable<HttpResult<UseBean>> regist = netApi.noticeInfo(id);
        RetrofitUtils.getInstance().toSubscribe(regist, subscriber);
    }

    /**
     * banner列表接口
     */
    public void bannerList(Subscriber<HttpResult<List<BannerBean>>> subscriber) {
        final Observable<HttpResult<List<BannerBean>>> regist = netApi.bannerList();
        RetrofitUtils.getInstance().toSubscribe(regist, subscriber);
    }

    /**
     * 借款列表
     *
     * @param p           当前页数
     * @param level       1(HR),2(E),3(D),4(C),5(B),6(A),7(AA)
     * @param deal_status 借款状态:19(未开始),1(进行中),2(满标),3(流标),4(还款中),5(已还清)
     * @param interest    回馈利率:10(10%以上),12(12%以上),15(15%以上),18(18%以上)
     * @param lefttime    剩余时间:1(1天以内),3(3天以内),6(6天以内),9(9天以内),12(12天以内)
     * @param is_company  借款用户:1(个人借款),2(企业借款)
     * @param months_type 借款期限:1(3个月以内),2(3-6个月),3(6-9个月),4(9-12个月),5(12个月以上)
     */
    public void loanlist(@Query("p") String p, @Query("level") String level, @Query("deal_status") String deal_status, @Query("interest") String interest, @Query("lefttime") String lefttime, @Query("is_company") String is_company, @Query("months_type") String months_type, Subscriber<HttpResult<List<UseBean>>> subscriber) {
        final Observable<HttpResult<List<UseBean>>> regist = netApi.loanlist(p, level, deal_status, interest, lefttime, is_company, months_type);
        RetrofitUtils.getInstance().toSubscribe(regist, subscriber);
    }

    /**
     * 借款标的详情
     */
    public void dealview(@Query("id") String id, Subscriber<BidDetailsBean> subscriber) {
        final Observable<BidDetailsBean> regist = netApi.dealview(id);
        RetrofitUtils.getInstance().toSubscribe(regist, subscriber);
    }

    /**
     * 设置支付密码接口
     */
    public void addpaypwd(@Query("token") String token, @Query("password") String password, @Query("repassword") String repassword, Subscriber<HttpResult> subscriber) {
        final Observable<HttpResult> regist = netApi.addpaypwd(token, password, repassword);
        RetrofitUtils.getInstance().toSubscribe(regist, subscriber);
    }

    /**
     * 修改支付密码接口
     */
    public void modifyPaypwd(@Query("mobile_email") String mobile_email, @Query("password") String password, @Query("repassword") String repassword, @Query("code") String code, Subscriber<HttpResult> subscriber) {
        final Observable<HttpResult> regist = netApi.modifyPaypwd(mobile_email, password, repassword, code);
        RetrofitUtils.getInstance().toSubscribe(regist, subscriber);
    }

    /**
     * 获取后台所有支持银行
     */
    public void getbankList(Subscriber<HttpResult<List<UseBean>>> subscriber) {
        final Observable<HttpResult<List<UseBean>>> regist = netApi.getbankList();
        RetrofitUtils.getInstance().toSubscribe(regist, subscriber);
    }

    /**
     * 绑定银行卡手机验证码接口
     */
    public void sendBindcardCode(@Query("user_mobile") String user_mobile, @Query("token") String Token, Subscriber<HttpResult> subscriber) {
        final Observable<HttpResult> regist = netApi.sendBindcardCode(user_mobile, Token);
        RetrofitUtils.getInstance().toSubscribe(regist, subscriber);
    }

    /**
     * 投标接口
     */
    public void bid(@Query("token") String token, @Query("id") String id, @Query("bid_money") String bid_money, @Query("interestrate_id") String interestrate_id, Subscriber<HttpResult> subscriber) {
        final Observable<HttpResult> regist = netApi.bid(token, id, bid_money, interestrate_id);
        RetrofitUtils.getInstance().toSubscribe(regist, subscriber);
    }

    /**
     * 上上签接口
     */
    public void shangshangqian(@Query("token") String token, Subscriber<HttpResult> subscriber) {
        final Observable<HttpResult> regist = netApi.shangshangqian(token);
        RetrofitUtils.getInstance().toSubscribe(regist, subscriber);
    }

    /**
     * 我的邀请列表
     *
     * @param type                 1：未投资    ，0：已投资
     * @param token                用户身份
     * @param page                 页码
     * @param httpResultSubscriber 。。。
     */
    public void myInvite(@Query("type") int type, @Query("token") String token, @Query("p") int page, Subscriber<HttpResult<List<RecommendAwardBean>>> httpResultSubscriber) {
        final Observable<HttpResult<List<RecommendAwardBean>>> myInvite = netApi.myinvite(type, token, page);
        RetrofitUtils.getInstance().toSubscribe(myInvite, httpResultSubscriber);
    }

    /**
     * 红包
     *
     * @param type       1=>'我的加息券列表',2=>'我的节日红包列表',3=>'我的8888现金红包活动列表'
     * @param type2      1：未使用，2：已使用  3：已过期
     * @param token      用户身份
     * @param page       页码
     * @param subscriber 。。。
     */
    public void myVoucher(@Query("type") int type, @Query("type2") int type2, @Query("token") String token, @Query("p") int page, Subscriber<HttpResult<List<RedPacketBean>>> subscriber) {
        final Observable<HttpResult<List<RedPacketBean>>> httpResultObservable = netApi.myVoucher(type, type2, token, page);
        RetrofitUtils.getInstance().toSubscribe(httpResultObservable, subscriber);
    }

    /**
     * 借款管理
     *
     * @param type
     * @param token
     * @param page
     * @param httpResultSubscriber
     */
    public void myBorrow(@Query("type") int type, @Query("token") String token, @Query("p") int page, Subscriber<HttpResult<List<LendRecordBean>>> httpResultSubscriber) {
        final Observable<HttpResult<List<LendRecordBean>>> listObservable = netApi.myBorrow(type, token, page);
        RetrofitUtils.getInstance().toSubscribe(listObservable, httpResultSubscriber);
    }

    /**
     * 我的资金管理
     */
    public void myLog(@Query("type") int type, @Query("token") String token, @Query("p") int page, Subscriber<HttpResult<List<CapitalLogBean>>> httpResultSubscriber) {
        final Observable<HttpResult<List<CapitalLogBean>>> httpResultObservable = netApi.myLog(token, type, page);
        RetrofitUtils.getInstance().toSubscribe(httpResultObservable, httpResultSubscriber);
    }

    /**
     * 用户接口
     */
    public void getUserInfo(@Query("token") String token, Subscriber<HttpResult<UserBean>> httpResultSubscriber) {
        final Observable<HttpResult<UserBean>> userInfo = netApi.getUserInfo(token);
        RetrofitUtils.getInstance().toSubscribe(userInfo, httpResultSubscriber);

    }

    /**
     * 提现
     */
    public void withDraw(@QueryMap HashMap<String, String> stringHashMap, Subscriber<HttpResult> draw) {
        final Observable<HttpResult> httpResultObservable = netApi.withDraw(stringHashMap);
        RetrofitUtils.getInstance().toSubscribe(httpResultObservable, draw);
    }

    /**
     * 编辑资料
     */

    public void editPersonal(@QueryMap HashMap<String, String> stringHashMap, Subscriber<HttpResult> resultSubscriber) {
        final Observable<HttpResult> httpResultObservable = netApi.editPersonal(stringHashMap);
        RetrofitUtils.getInstance().toSubscribe(httpResultObservable, resultSubscriber);
    }

    /**
     * 获取银行卡列表
     */
    public void getMyBankList(@Query("token") String token, @Query("act") String act, Subscriber<HttpResult<List<MyBankCardBean>>> resultSubscriber) {
        final Observable<HttpResult<List<MyBankCardBean>>> myBankList = netApi.getMyBankList(token, act);
        RetrofitUtils.getInstance().toSubscribe(myBankList, resultSubscriber);
    }

    /**
     * 添加银行卡
     */
    public void addBank(@Query("token") String token, @Query("real_name") String real_name, @Query("bankzone") String bankzone, @Query("bank_id") String bank_id, @Query("bankcard") String bankcard, @Query("user_mobile") String user_mobile, @Query("code") String code, Subscriber<HttpResult> resultSubscriber) {
        final Observable<HttpResult> myBankList = netApi.addBank(token, real_name, bankzone, bank_id, bankcard, user_mobile, code);
        RetrofitUtils.getInstance().toSubscribe(myBankList, resultSubscriber);
    }

    /**
     * 删除银行卡
     */
    public void deleteBank(@Query("token") String token, @Query("act") String act, @Query("id") String id, Subscriber<HttpResult> resultSubscriber) {
        final Observable<HttpResult> myBankList = netApi.deleteBankList(token, act, id);
        RetrofitUtils.getInstance().toSubscribe(myBankList, resultSubscriber);
    }

    /**
     * 认证
     */
    public void renzheng(@Query("token") String token, @Query("real_name") String real_name, @Query("idno") String idno, Subscriber<HttpResult> httpResultSubscriber) {
        final Observable<HttpResult> renzheng = netApi.renzheng(token, real_name, idno);
        RetrofitUtils.getInstance().toSubscribe(renzheng, httpResultSubscriber);
    }

    /**
     * 退出
     */
    public void logout(@Query("token") String token, Subscriber<HttpResult> httpResultSubscriber) {
        final Observable<HttpResult> logout = netApi.logout(token);
        RetrofitUtils.getInstance().toSubscribe(logout, httpResultSubscriber);
    }

    /**
     * 充值
     *
     * @param hashMap              请求参数
     * @param httpResultSubscriber 订阅者
     */
    public void recharge(@QueryMap HashMap<String, String> hashMap, Subscriber<RechargeBean> httpResultSubscriber) {
        final Observable<RechargeBean> recharge = netApi.recharge(hashMap);
        RetrofitUtils.getInstance().toSubscribe(recharge, httpResultSubscriber);
    }


    /**
     * 获取富有配置
     *
     * @param httpResultSubscriber
     */
    public void getFyConfig(Subscriber<FyBean> httpResultSubscriber) {
        final Observable<FyBean> fyConfig = netApi.getFyConfig();
        RetrofitUtils.getInstance().toSubscribe(fyConfig, httpResultSubscriber);
    }

    /**
     * 体现验证码
     *
     * @param token
     * @param user_mobile
     * @param httpResultSubscriber
     */
    public void getDepositCode(@Query("token") String token, @Query("user_mobile") String user_mobile, Subscriber<HttpResult> httpResultSubscriber) {
        final Observable<HttpResult> depositCode = netApi.getDepositCode(token, user_mobile);
        RetrofitUtils.getInstance().toSubscribe(depositCode, httpResultSubscriber);
    }

    /**
     * 上传头像
     *
     * @param httpResultSubscriber
     */
    public void upImg(@Body RequestBody Body, Subscriber<HttpResult> httpResultSubscriber) {
        final Observable<HttpResult> httpResultObservable = netApi.upLoad(Body);
        RetrofitUtils.getInstance().toSubscribe(httpResultObservable, httpResultSubscriber);

    }
}
